Completed
Push — master ( 57c78c...4fcad4 )
by Muhammad Dyas
15s queued 13s
created

option.ts ➔ addOptionToState   A

Complexity

Conditions 2

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 16
rs 10
c 0
b 0
f 0
cc 2
1
import {PollState} from './interfaces';
2
3
/**
4
 * Add a new option to the state(like DB)
5
 *
6
 * @param {string} option - the new option name
7
 * @param {object} state - the current message state
8
 * @param {string} creator - who add the new option
9
 * @returns {void} card
10
 */
11
export function addOptionToState(option: string, state: PollState, creator = '') {
12
  const choiceLength = state.choices.length;
13
  state.choices.push(option);
14
  if (state.choiceCreator === undefined) {
15
    state.choiceCreator = {[choiceLength]: creator};
16
  } else {
17
    state.choiceCreator[choiceLength] = creator;
18
  }
19
}
20